package health

import (
	"gitee.com/g-qs/gin-vue-admin/server/global"
	"gitee.com/g-qs/gin-vue-admin/server/model/common/request"
	"gitee.com/g-qs/gin-vue-admin/server/model/common/response"
	"gitee.com/g-qs/gin-vue-admin/server/model/health"
	healthReq "gitee.com/g-qs/gin-vue-admin/server/model/health/request"
	"gitee.com/g-qs/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type FdEfficacyApi struct {
}

var fdEfficacyService = service.ServiceGroupApp.HealthServiceGroup.FdEfficacyService

// CreateFdEfficacy 创建功效
// @Tags FdEfficacy
// @Summary 创建功效
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body health.FdEfficacy true "创建功效"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /fdEfficacy/createFdEfficacy [post]
func (fdEfficacyApi *FdEfficacyApi) CreateFdEfficacy(c *gin.Context) {
	var fdEfficacy health.FdEfficacy
	err := c.ShouldBindJSON(&fdEfficacy)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdEfficacyService.CreateFdEfficacy(&fdEfficacy); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteFdEfficacy 删除功效
// @Tags FdEfficacy
// @Summary 删除功效
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body health.FdEfficacy true "删除功效"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fdEfficacy/deleteFdEfficacy [delete]
func (fdEfficacyApi *FdEfficacyApi) DeleteFdEfficacy(c *gin.Context) {
	var fdEfficacy health.FdEfficacy
	err := c.ShouldBindJSON(&fdEfficacy)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdEfficacyService.DeleteFdEfficacy(fdEfficacy); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteFdEfficacyByIds 批量删除功效
// @Tags FdEfficacy
// @Summary 批量删除功效
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除功效"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /fdEfficacy/deleteFdEfficacyByIds [delete]
func (fdEfficacyApi *FdEfficacyApi) DeleteFdEfficacyByIds(c *gin.Context) {
	var IDS request.IdsReq
	err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdEfficacyService.DeleteFdEfficacyByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateFdEfficacy 更新功效
// @Tags FdEfficacy
// @Summary 更新功效
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body health.FdEfficacy true "更新功效"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /fdEfficacy/updateFdEfficacy [put]
func (fdEfficacyApi *FdEfficacyApi) UpdateFdEfficacy(c *gin.Context) {
	var fdEfficacy health.FdEfficacy
	err := c.ShouldBindJSON(&fdEfficacy)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdEfficacyService.UpdateFdEfficacy(fdEfficacy); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindFdEfficacy 用id查询功效
// @Tags FdEfficacy
// @Summary 用id查询功效
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query health.FdEfficacy true "用id查询功效"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /fdEfficacy/findFdEfficacy [get]
func (fdEfficacyApi *FdEfficacyApi) FindFdEfficacy(c *gin.Context) {
	var fdEfficacy health.FdEfficacy
	err := c.ShouldBindQuery(&fdEfficacy)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if refdEfficacy, err := fdEfficacyService.GetFdEfficacy(fdEfficacy.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"refdEfficacy": refdEfficacy}, c)
	}
}

// GetFdEfficacyList 分页获取功效列表
// @Tags FdEfficacy
// @Summary 分页获取功效列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query healthReq.FdEfficacySearch true "分页获取功效列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdEfficacy/getFdEfficacyList [get]
func (fdEfficacyApi *FdEfficacyApi) GetFdEfficacyList(c *gin.Context) {
	var pageInfo healthReq.FdEfficacySearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := fdEfficacyService.GetFdEfficacyInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

func (fdEfficacyApi *FdEfficacyApi) SetFdEfficacyGraphic(c *gin.Context) {
	var req healthReq.FdEfficacyArticleReq
	err := c.ShouldBindJSON(&req)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdEfficacyService.SetFdEfficacyGraphic(req); err != nil {
		global.GVA_LOG.Error("设置失败!", zap.Error(err))
		response.FailWithMessage("设置失败", c)
	} else {
		response.OkWithMessage("设置成功", c)
	}
}

func (fdEfficacyApi *FdEfficacyApi) GetFdEfficacyGraphic(c *gin.Context) {
	fd_efficacy_id := c.Query("fd_efficacy_id")
	if res, err := fdEfficacyService.GetFdEfficacyGraphic(fd_efficacy_id); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithData(res, c)
	}
}
